﻿using System;
using System.CodeDom;
using static System.Console;
// ReSharper disable AssignNullToNotNullAttribute

namespace App.Console
{
    internal class Program
    {

        private const string Abcd = "abcd";

        private static void Main(string[] args)
        {
            //Console.WriteLine("10 -1  2  0 |   6\n-1 11 -1  3 |  25\n 2 -1 10 -1 | -11\n 0  3 -1  8 |  15");
            //Console.ReadKey();
            //Console.Clear();
            RunNewtonRaphson();
            ReadKey();
            //RunGauss();
            //Console.ReadKey();
            //RunJacobi();
            //Console.ReadKey();
            //RunSeidel();
            //Console.ReadKey();
            //RunLinearRegression();

        }

        private static void RunJacobi()
        {
            System.Console.WriteLine("Gauss");
            System.Console.WriteLine();

            var array = new double[,] { { 10, -1, 2, 0 }, { -1, 11, -1, 3 }, { 2, -1, 10, -1 }, { 0, 3, -1, 8 } };
            var constants = new double[] { 6, 25, -11, 15 };

            Jacobi.Solve(array, constants);
        }

        public static void RunGauss()
        {
            var gaussJordan = new Gauss();

            System.Console.WriteLine("Gauss");
            System.Console.WriteLine();


            System.Console.Write("Número de linhas: 4\n");
            System.Console.Write("Número de colunas: 5\n\n");

            var array = new float[,] { { 10, -1, 2, 0, 6 }, { -1, 11, -1, 3, 25 }, { 2, -1, 10, -1, -11 }, { 0, 3, -1, 8, 15 } };

            try
            {
                gaussJordan.Solve(array);
            }
            catch (ArgumentException ex)
            {
                System.Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }

            var rows = 4;
            for (var i = 0; i < rows; i++)
            {
                for (var k = 0; k < rows + 1; k++)
                {
                    System.Console.Write(gaussJordan.Result[i, k] + " | ");
                }

                System.Console.WriteLine();
            }

            System.Console.Write("Pressione alguma tecla para continuar...");
            System.Console.ReadKey();
        }

        public static void RunSeidel()
        {
            var gaussSeidel = new GaussSeidel();

            System.Console.WriteLine("Seidel\n");
            System.Console.WriteLine();

            var no = 4;
            var tol = 1000;

            var mtrx = new float[,] { { 10, -1, 2, 0 }, { -1, 11, -1, 3 }, { 2, -1, 10, -1 }, { 0, 3, -1, 8 } };
            var b = new float[] { 6, 25, -11, 15 }; ;

            gaussSeidel.Solve(mtrx, b, no, tol); // Finding the values of X in Different Iterations  

            System.Console.ReadLine();
        }

        public static void RunNewtonRaphson()
        {
            NewtonRaphson.Solve(-1.5, NewtonRaphson.QuadraticFunction, NewtonRaphson.DevQuadraticFunction);
            System.Console.ReadKey();
        }

        public static void RunLinearRegression()
        {

            //var arrayX = new double[] {1.2,2.3,3.0,3.8,4.7,5.9};
            //var arrayY = new double[] {1.1,2.1,3.1,4.0,4.9,5.9};

            var arrayX = new[] {1d,2d,3d,4d,5d,6d,7d};
            var arrayY = new[] {0.5,2.5,2.0,4.0,3.5,6.0,5.5};

            var lr = new LinearRegression(arrayX,arrayY);

        }
    }
}